package org.blogwu.learn.multithread.chapter3.demo18.v1;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MainV1 extends Thread {

    /**
     * Wed Oct 10 22:20:53 CST 2018
     * Fri Apr 10 22:20:53 CST 20182201
     * Fri Apr 10 22:20:53 CST 20182201
     * <p>
     * 会出现线程安全问题
     */
//    private static final ThreadLocal t2=new ThreadLocal(new Supplier(() -> 1231) {
//        @Override
//        public Object get() {
//            return null;
//        }
//    });

    private static final SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public void run() {
        try {
            Date d = sp.parse("2018-10-10 22:20:53");
            System.out.println(d);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        ExecutorService executors = Executors.newFixedThreadPool(1000);
        for (int i = 0; i < 100000; i++) {
            executors.submit(new MainV1());
        }
        executors.shutdown();
        long endTime = (System.currentTimeMillis() - start) / 1000;
        System.out.println("end:" + endTime);
    }
}
